<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
export default {
  name: 'App',
  computed: {
    listenWebsocket() {
      return this.$store.state.websocket.message
    },
    listenLoginStatus() {
      return this.$store.getters.name
    }
  },
  watch: {
    listenWebsocket: function(newstr) {
      const form = JSON.parse(newstr)
      if (form.message === 'new dialog') {
        const msg = Object.assign({}, JSON.parse(form.items))
        if (msg.sender.id !== this.$store.getters.id && !this.$route.path.includes('/inform/')) {
          this.$notify({
            title: msg.sender.name,
            message: (msg.content.length > 25 ? msg.content.substring(0, 25) + '...' : msg.content),
            type: 'success',
            duration: 4000
          })
        }
      }
    },
    listenLoginStatus: function(newstr) {
      this.$store.dispatch('websocket/WEBSOCKET_INIT', 'ws://localhost:8080/webSocket/' + newstr)
    }
  }
}
</script>
